package com.example.demo.concurrent.AtomicTest.Atomic;

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-03-14
 * Time: 20:19
 */
public class AtomicReferenceFileUpdater {
    /**
     * 原子更新器
     * @param args
     */
    public static void main(String[] args) {
        Student1 student1 = new Student1();
        AtomicReferenceFieldUpdater updater =
                AtomicReferenceFieldUpdater.newUpdater(Student1.class,String.class,"name");
        boolean stuName = updater.compareAndSet(student1, null, "张三");
        System.out.println(stuName);
        System.out.println(student1);

    }
}
class Student1 {
    volatile String name;

    @Override
    public String toString() {
        return "Student1{" +
                "name='" + name + '\'' +
                '}';
    }
}
